package com.bjpowernode.springboot.config;

import com.bjpowernode.springboot.Filter.CharacterFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@SuppressWarnings("all")
@Configuration // 将该类声明为Filter的配置类，主要是将自定义的过滤器注册到spring中
public class CharacterFilterConfiguration {
    /**
     * 注入FilterRegistionBean实体用于注册
     * @return
     */
    @Bean
    public FilterRegistrationBean filterRegistrationBean() {
        FilterRegistrationBean filterRegistrationBean = new FilterRegistrationBean();
        CharacterFilter characterFilter = new CharacterFilter(); // 创建自定义过滤器
        filterRegistrationBean.setFilter(characterFilter); // 注册
        /*注意这里只能写一个*,否则无法识别 */
        filterRegistrationBean.addUrlPatterns("/filter-test/test/*"); // 添加过滤路径
        return filterRegistrationBean;
    }
}
